﻿using SF.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SF.Ucenter.admin.statistics
{
    public partial class quarterapplist : System.Web.UI.Page
    {
        protected string[] orders_Tendency = new string[] { "", "", "" };
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session[DTKeys.SESSION_BUSNIESE_NUM] != null)
            {
                string businessNum = Session[DTKeys.SESSION_BUSNIESE_NUM].ToString(); 
                orders_Tendency = GetQuarterDataByBusinessNum(businessNum);
            }
        }

        private string[] GetQuarterDataByBusinessNum(string businessNum)
        {
            DateTime startday = DateTime.Now;
            string strStartTime = startday.AddYears(-1).ToString("yyyy");
            string strEndTime = startday.ToString("yyyy");

            BLL.statistics bll = new BLL.statistics();
            System.Data.DataSet dsOrders = bll.GetQuarterDataByBusinessNum(businessNum, strStartTime, strEndTime);


            int month = int.Parse(startday.ToString("MM"));
            string xAxis = "";
            string yAxis0 = "";//今年
            string yAxis1 = "";//去年

            for (int i = 1; i <= month; i++)
            {
                xAxis += "'"+i + "月',";
                string strMonth = "";
                if (i < 10)
                {
                    strMonth = "0" + i;
                }
                else
                {
                    strMonth = i.ToString();
                }

                System.Data.DataRow[] rows0 = dsOrders.Tables[0].Select("day='" + strEndTime + "-" + strMonth + "'");
                System.Data.DataRow[] rows1 = dsOrders.Tables[0].Select("day='" + strStartTime + "-" + strMonth + "'");

                if (rows0.Length > 0)
                {
                    yAxis0 += rows0[0]["count"] + ",";
                }
                else
                {
                    yAxis0 += "0,";
                }

                if (rows1.Length > 0)
                {
                    yAxis1 += rows1[0]["count"] + ",";
                }
                else
                {
                    yAxis1 += "0,";
                }
            }


            if (xAxis.Length > 0)
            {
                xAxis = xAxis.Remove(xAxis.Length - 1, 1);
                yAxis0 = yAxis0.Remove(yAxis0.Length - 1, 1);
                yAxis1 = yAxis1.Remove(yAxis1.Length - 1, 1);
            }

            return new[] { xAxis, yAxis0, yAxis1 };
        }
    }
}